var wxUtil = require('wxUtil');
cc.Class({
    extends: cc.Component,

    properties: {
    	markBg:{
            default: null,
            type: cc.Node
        },
        display:{
            default: null,
            type: cc.Sprite
        },
        sClick:{
            default:null,
            url:cc.AudioClip
        },
        spaceTime: 1.5,
        btnPageUp:cc.Node,
        btnPageDown:cc.Node,
    },

    onLoad () {
	    let openDataContext = wx.getOpenDataContext();
	    openDataContext.postMessage({message:'GET_TOP_BY_DLG_RANK'});
	    //只能在主域设置大小, 且要先于赋值到sprite才起作用
	    var sharedCanvas = openDataContext.canvas;
	    sharedCanvas.width = this.display.node.width;
	    sharedCanvas.height = this.display.node.height;
	    this.t_count =0;
    },

    start () {
        this.tex = new cc.Texture2D();
    },

    btnClose:function(){
        // let openDataContext = wx.getOpenDataContext();
        // openDataContext.postMessage({message:'CLOSE_RANK_LIST'});
        if(gGlobal.gVoice)
            cc.audioEngine.play(this.sClick,false);
        this.node.active = false;
        wxUtil.showBanner();
    },

    setShow(){
		this.node.active = true;
        wxUtil.showBanner();
    },

    update (dt) {
        if(this.node.active){
            this._updaetSubDomainCanvas();
        }
    },
    _updaetSubDomainCanvas () {
        if (!this.tex) {
            return;
        }
        var openDataContext = wx.getOpenDataContext();
        var sharedCanvas = openDataContext.canvas;
        this.tex.initWithElement(sharedCanvas);
        this.tex.handleLoadedTexture();
        this.display.spriteFrame = new cc.SpriteFrame(this.tex);
    },
    clickPageUp(){
        if(gGlobal.gVoice)
            cc.audioEngine.play(this.sClick,false);
        // console.log("-----btnPageUp");
        let openDataContext = wx.getOpenDataContext();
        openDataContext.postMessage({message:'PAGE_UP'});
    },
    clickPageDown(){
        if(gGlobal.gVoice)
            cc.audioEngine.play(this.sClick,false);
        // console.log("-----clickPageDown");
        let openDataContext = wx.getOpenDataContext();
        openDataContext.postMessage({message:'PAGE_DOWN'});
    },
});
